package com.tsl.prevention.modules.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsl.prevention.modules.user.entity.Record;
import com.tsl.prevention.modules.user.service.IRecordService;
import com.tsl.prevention.util.PageFilter;
import com.tsl.prevention.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * <p>
 * 出行记录表 前端控制器
 * </p>
 *
 * @author Lionel
 * @since 2021-03-20
 */
@RestController
@RequestMapping("/user/record")
@Api
public class RecordController {
    @Autowired
    IRecordService iRecordService;

    @PostMapping("/add")
    @ApiOperation("根据openId完成出行")
    public Result add(String openId, String temp) {
        //查询用户信息
        return Result.create(iRecordService.addByOpenId(openId, temp));
    }

    @GetMapping("/getList")
    @ApiOperation("查询全部的出行记录")
    public Result getList(PageFilter pageFilter,String openId) {
        Page page = new Page(pageFilter.getStart(), pageFilter.getSize());
        IPage<HashMap<String, String>> mapIPage = iRecordService.getList(page,openId);
        return Result.create(mapIPage);
    }

//    @GetMapping("/getListByOpenid")
//    @ApiOperation("根据opneID查询出行记录")
//    public Result getListByOpenid(String openId,PageFilter pageFilter) {
//        Page page = new Page(pageFilter.getStart(), pageFilter.getSize());
//        IPage<Record> user_id = iRecordService.page(page, new QueryWrapper<Record>().eq("user_id", openId));
//        return Result.create(user_id.getRecords());
//    }

}

